package org.NooLab.itexx.app.gui.definition;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.plaf.ScrollBarUI;
import javax.swing.plaf.basic.BasicScrollBarUI;

import org.NooLab.itexx.browser.DjBrowserHostIntf;

import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;

public class ITexxWindowGuiFormSettings {

	
	private ITexxWindowGuiIntf windowGui;
	private Object scrollpane;

	public ITexxWindowGuiFormSettings(ITexxWindowGuiIntf gui){
		windowGui = gui; 
		windowGui.setSettingsProvider(this);
	}
	
	public void setClassic(){
		
		// windowGui.getjPanelScrollDummy().setVisible(false);
		
		windowGui.getMainToolBar().setVisible(false);
		windowGui.getjPanelHistoryTree().setVisible(false);
		windowGui.getjPanelPGraphics().setVisible(false) ;
		
		if (windowGui.getTabbedPaneMain().getTabCount()>3){
			windowGui.getTabbedPaneMain().removeTabAt(3);
			windowGui.getTabbedPaneMain().removeTabAt(1);
		}

		
		windowGui.getNewButton().setText("n");
		windowGui.getOpenButton().setText("o");
		windowGui.getSaveButton().setText("s");
		windowGui.getjButtonSingleWindow().setText("w");
		
		
		windowGui.getNewButton().setVisible(false);
		windowGui.getOpenButton().setVisible(false);
		windowGui.getSaveButton().setVisible(false);
		
		int h = windowGui.getjPanelFoundScrollerHost().getHeight() ;
		
		customizeVerticalScrollBar();
		
		
		// windowGui.getScrollPaneReturnedResults().setPreferredSize( new Dimension(200,h) );
		
		// apply any background graphics via the label technique
	}
	

	private void customizeVerticalScrollBar() {
		// 
		
		int h=(int) windowGui.getScrollPaneReturnedResults().getVerticalScrollBar().getPreferredSize().getHeight();
		windowGui.getScrollPaneReturnedResults().getVerticalScrollBar().setPreferredSize(new Dimension(15,h)) ;
		
		
	}

	public void applyBackgroundImage( Container con, String imagePath) throws IOException{
		
		BufferedImage myPicture = ImageIO.read(new File("path-to-file"));
		JLabel picLabel = new JLabel(new ImageIcon( myPicture ));
		con.add( picLabel );

		// The image is now a swing component. It becomes subject to layout conditions like any other component.
	}
	
	static class NimbusScrollbarUI extends BasicScrollBarUI {
	    private Image imageThumb, imageTrack;
	    NimbusScrollbarUI() {
	        try {
	            // imageThumb = ImageIO.read(new File("thumb.png"));
	            // imageTrack = ImageIO.read(new File("track.png"));
	        } catch (Exception e){}
	    }

	    @Override
	    protected void paintThumb(final Graphics g, final JComponent c, final Rectangle thumbBounds) {
	        if (thumbBounds.isEmpty() || !this.scrollbar.isEnabled()) {
	            return;
	        }
	        int tx=(int) (thumbBounds.x *0.6);
	        g.translate(tx, thumbBounds.y);
	        g.setColor(this.thumbDarkShadowColor);
	        g.drawOval(2, 0, 14, 14);
	        g.setColor(this.thumbColor);
	        g.fillOval(2, 0, 14, 14);
	        g.setColor(this.thumbHighlightColor);
	        g.setColor(this.thumbLightShadowColor);
	        g.translate(-thumbBounds.x, -thumbBounds.y);
	    }


	    // @Override
	    protected void _paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {        
	        g.translate(trackBounds.x, trackBounds.y);
	        ((Graphics2D)g).drawImage(imageTrack,AffineTransform.getScaleInstance(1,(double)trackBounds.height/imageTrack.getHeight(null)),null);
	        g.translate( -trackBounds.x, -trackBounds.y );
	    }

	  }

}
